<?php

namespace addons\unishop\controller;

use app\common\controller\Api;
use think\Cache;
use think\Lang;
use app\common\library\Upload;

/**
 * 基础类
 * @ApiInternal
 */
class Uploads extends Api
{
    /**
     * 无需鉴权的方法,但需要登录
     * @var array
     */
    protected $noNeedRight = ['*'];
    protected $noNeedLogin = ['*'];
    /**
     * 允许频繁访问的接口（方法格式：小写）
     * @var array
     */
    protected $frequently = [];

    /**
     * 上传文件
     * @ApiMethod (POST)
     * @param File $file 文件流
     */
    public function upload()
    {

            $attachment = null;
            //默认普通上传文件
            $file = $this->request->file('file');
            try {
                $upload = new Upload($file);
                $attachment = $upload->upload();
            } catch (UploadException $e) {
                $this->error($e->getMessage());
            }

            $this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);


    }

}